﻿//using System.Windows;
//using System.Windows.Controls;
//using System.Windows.Controls.Primitives;
//using System.Windows.Media.Imaging;
//using Microsoft.SilverlightMediaFramework.Utilities.Extensions;

//namespace JustinAngel.Neurons
//{
//    public class ImageTransition : ContentControl
//    {

//        #region TargetImage (DependencyProperty)

//        /// <summary>
//        /// Gets or sets the target image which will be transitioned out.
//        /// </summary>
//        public Image TargetImage
//        {
//            get { return (Image)GetValue(TargetImageProperty); }
//            set { SetValue(TargetImageProperty, value); }
//        }
//        public static readonly DependencyProperty TargetImageProperty =
//            DependencyProperty.Register("TargetImage", typeof(Image), typeof(ImageTransition),
//                                        new PropertyMetadata(null));

//        #endregion

//        public void Transition(Image targetImage)
//        {
//            this.TargetImage = targetImage;
//            Transition();
//        }

//        public void Transition()
//        {
//            if (TargetImage == null) return;

//            var copyOfImage = GetImageWithAWriteableBitmapOfTargetImage();

//            var currentImageLocation = LayoutInformation.GetLayoutSlot(TargetImage);
            
//            this.Margin = new Thickness(currentImageLocation.Left, currentImageLocation.Top, currentImageLocation.Right, currentImageLocation.Bottom);

//            this.Content = copyOfImage;

//            VisualStateManager.GoToState(this.GetVisualParent<UserControl>(), "TransitionImage", true);
//        }

//        private Image GetImageWithAWriteableBitmapOfTargetImage()
//        {
//            WriteableBitmap wb = new WriteableBitmap(TargetImage, null);

//            Image image = new Image();
//            image.Height = TargetImage.Height;
//            image.Width = TargetImage.Width;
//            image.Source = wb;

//            return image;
//        }


//        #region TargetImageForTransition (Attached DependencyProperty)

//        public static readonly DependencyProperty TargetImageForTransitionProperty =
//            DependencyProperty.RegisterAttached("TargetImageForTransition", typeof(Image), typeof(ImageTransition), new PropertyMetadata(new PropertyChangedCallback(OnTargetImageForTransitionChanged)));

//        public static void SetTargetImageForTransition(Button o, Image value)
//        {
//            o.SetValue(TargetImageForTransitionProperty, value);
//        }

//        public static Image GetTargetImageForTransition(Button o)
//        {
//            return (Image)o.GetValue(TargetImageForTransitionProperty);
//        }

//        private static void OnTargetImageForTransitionChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
//        {
//            var sender = d as Button;
//            var value = e.NewValue as Image;

//            if (value != null && sender != null)
//            {
//                sender.Click += (s, args) =>
//                                sender.GetVisualParent<UserControl>().GetVisualChild<ImageTransition>().Transition(value);
//            }
//        }

//        #endregion

//    }
//}